<template>
  <div class="buy-car-box">
    <Header />
    <div class="nav-outer">
      <div class="nav-1200 area1190">
        <span>首页</span> > <span>商城首页</span> > <span>在线购车</span> >
        <div class="nav-right">
          <span>售后政策</span>
          <i class="center-line"></i>
          <span @click="openBuy">咨询客服</span>
        </div>
      </div>
    </div>
    <!-- 内容块 -->
    <div class="middle-box">
      <div class="content-box">
        <div class="title">在线购车</div>
        <p>敬请填写以下信息，我们将尽快为您奉上详尽的购车咨询服务！</p>
        <div class="flex">
          <div class="input-box">
            <div class="input-item flex ai-c">
              <span>主要用途：</span>
              <el-select v-model="value" placeholder="请选择" class="form-el">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </div>
            <div class="input-item flex ai-c">
              <span>您的姓名：</span>
              <el-input
                v-model="name"
                placeholder="请输入您的姓名"
              ></el-input>
            </div>
            <div class="input-item flex ai-c">
              <span>您的电话：</span>
              <el-input
                v-model="phone"
                placeholder="请输入您的电话"
              ></el-input>
            </div>
            <div class="input-item flex textarea-el">
              <span>您的需求：</span>
              <el-input
                v-model="content"
                type="textarea"
                placeholder="请输入您的需求"
                rows="5"
              ></el-input>
            </div>
            <div class="flex jc-sb">
              <div class="btn btn-success" @click="submitTo">我要购车</div>
              <div class="btn" @click="openBuy">客服购车</div>
            </div>
          </div>
          <div class="flex-1 three-car-box">
            <img src="@/assets/buyCar/three-car.jpg" alt="" srcset="" />
            <div class="phone-box">
              <i>400-642-0006</i>
              <div class="remarks">江铃24小时客服热线</div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <Footer />
  </div>
</template>

<script>
import Header from "@/components/Header.vue";
import Footer from "@/components/Footer.vue";
import empty from "../utils/common";
export default {
  name: "CarCenter",
  components: {
    Header,
    Footer,
  },
  data() {
    return {
      options: [
        {
          value: "1",
          label: "售前",
        },
        {
          value: "2",
          label: "售后",
        },

      ],
      value: "1",
      name: "",
      content: "",
      phone: "",
    };

  },
  methods:{
      submitTo(){
          if(empty(this.name)){
              this.$message({
                  showClose: true,
                  message: '姓名不能为空',
                  type: 'warning'
              });
              return false;
          }
          if(empty(this.phone)){
              this.$message({
                  showClose: true,
                  message: '手机号不能为空',
                  type: 'warning'
              });
              return false;
          }
          //手机号校验
          let url = '/form/sendMessages?';
          url+='content='+this.content;
          url+='&name='+this.name;
          url+='&phone='+this.phone;
          url+='&type='+this.value;
          if(!this.checkPhone(this.phone)){return false;
          }
          this.$http.get(url).then(response=> {
              this.$message({
                  showClose: true,
                  message: response.message,
                  type: 'success'
              });
          })
      },
      checkPhone(phone){
          var pattern = /^1[34578]\d{9}$/;
          if(!pattern.test(phone)){
              this.$message({
                  showClose: true,
                  message:'手机号有误',
                  type: 'error'
              });
              return false;
          }
          return true;
      },
      openBuy(){
        window.open('https://www10.53kf.com/webCompany.php?kf_sign=jA4MDMTYxMk4NzEwMDIxNDQyODUyMDI5NzIyNDY4NjI=&arg=10246862&style=1&guest_id=10021442852029&language=zh-cn&charset=GBK&referer=http%3A%2F%2F192.168.0.104%3A8080%2F%23%2FbuyCar&keyword=http%3A%2F%2F192.168.0.104%3A8080%2F&tpl=crystal_blue&uid=6ea8bb56dbb5407686d6f632ff280011&is_group=&tfrom=1', '_blank', 'height=600,width=800,top=50,left=200,status=yes,toolbar=no,menubar=no,resizable=no,scrollbars=no,location=no,titlebar=no')
      }
  }
};
</script>

<style lang="scss" scoped>
.middle-box {
  margin: 20px 0;
  .content-box {
    background: #fff;
    text-align: left;
  }
  .title {
    font-weight: normal;
    font-size: 20px;
    color: #565656;
    height: 70px;
    line-height: 70px;
    padding-left: 30px;
    border-bottom: 1px solid #f5f5f5;
    box-sizing: border-box;
  }
  p {
    font-size: 14px;
    color: #646464;
    line-height: 50px;
    padding-left: 30px;
  }
  .input-box {
    padding-left: 30px;
    box-sizing: border-box;
    padding-bottom: 50px;
  }
  .input-item {
    height: 50px;
    border: solid 1px #dcdcdc;
    padding-left: 20px;
    margin-bottom: 20px;
  }
  /deep/ .el-input {
    width: 450px;
  }
  /deep/ .el-textarea {
    width: 450px;
  }
  /deep/ .el-input__inner,
  /deep/ .el-textarea__inner {
    border: 0;
  }
  .textarea-el {
    height: auto;
    padding: 2px 0;
    padding-left: 20px;
    span {
      margin-top: 6px;
    }
  }
  .btn {
    width: 240px;
    line-height: 50px;
    background-color: #f3f3f3;
    opacity: 0.68;
    color: #333333;
    font-size: 14px;
    text-align: center;
    cursor: pointer;
    &.btn-success {
      background-color: #e20505;
      color: #f3f3f3;
    }
  }
  .three-car-box {
    position: relative;
    text-align: center;
    img {
      width: 85%;
      transform: translateY(-30px);
    }
    .phone-box {
      position: absolute;
      left: 50%;
      top: 35%;
      transform: translateX(-50%);
      text-align: center;
    }
    i {
      font-size: 30px;
      font-weight: bold;
      color: #373c3a;
    }
    .remarks {
      font-size: 14px;
      color: #777777;
    }
  }
}

/**手机端**/
@media (min-width: 320px) and (max-width: 800px) {
  .nav-outer {
    display: none;
  }
  .middle-box {
    height: calc(100% - 100px);
    overflow-y: auto;
    position: relative;

    .input-box {
      width: 100%;
    }
    .input-item {
      width: 90%;
    }
    /deep/ .el-input,.el-textarea {
      width: 260px;
    }
    .btn  {
      width: 164px;
      line-height: 40px;
      &:last-child {
        margin-right: 14px;
      }
    }
  }
  .middle-box .title {
    height: 50px;
    line-height: 50px;
  }
  .content-box {
    p {
      font-size: 12px;
      line-height: 30px;
      margin-top: 360px;
      padding-left: 6px;
      text-align: center;
    }
    .three-car-box {
      position: absolute;
      top: 100px;
      i {
        font-size: 20px;
      }
      .remarks {
        font-size: 12px;
      }
    }
    .input-box {
      padding-left: 14px;
    }
  }
}
</style>